<template>
  <div class="bg-content content">
    <div class="search-c">
      <img class="seaimg" src="../../../../assets/img/main/ss.jpg" alt="" />
      <input
        class="search"
        v-model="key"
        :placeholder="placeholderVal"
        type="text"
        @keyup.enter="go(key)"
      />
      <div class="go" @click="go(key)">搜索</div>
    </div>

    <div v-if="list.type == 1">
      <div class="nav">
        <div class="line"></div>
        <div class="tuijian">推荐医生({{ list.num }})</div>
      </div>
      <div class="search-list">
        <div class="item" v-for="(item, index) in doclist" :key="index">
          <div class="img" @click="godocinfo(item)">
            <img v-if="item.avatar" :src="item.avatar" alt="" />
            <img v-else src="../../../../assets/img/main/yisheng.png" alt="" />
          </div>
          <div class="docinfo">
            <div class="name" @click="godocinfo(item)">
              {{ item.doctorName }}<span>{{ item.doctorTitle }}</span>
            </div>
            <div class="hosname" @click="godocinfo(item)">
              {{ item.hospitalName }} <span>{{ item.departmentName }}</span>
            </div>
            <!-- <div class="goodinfo">{{item.goodAt}}</div> -->
            <div class="goodinfo">
              <div class="good-left">{{ item.goodAt }}</div>
              <div
                class="good-right"
                v-if="item.goodAt.length > 0"
                @click="goInfo(item.goodAt)"
              >
                更多>
              </div>
            </div>

            <div class="jiuzhennum">已就诊:{{ item.ghnum }}</div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="list.type == 2">
      <div class="nav">
        <div class="line"></div>
        <div class="tuijian">推荐科室({{ list.num }})</div>
      </div>
      <div class="search-list">
        <div
          class="item"
          @click="godoctor(item)"
          v-for="(item, index) in doclist"
          :key="index"
        >
          <div class="img">
            <img v-if="item.image" :src="item.image" alt="" />
            <img v-else src="../../../../assets/img/main/hos.png" alt="" />
          </div>
          <div class="docinfo">
            <div class="name">
              {{ item.hospitalName }}<span>{{ item.hospitalLevel }}</span>
            </div>
            <div class="hosname">{{ item.departmentName }}</div>
            <div class="goodinfo">{{ item.address }}</div>
            <!-- <div class="jiuzhennum">已就诊:20</div> -->
          </div>
        </div>
      </div>
    </div>
    <van-popup v-model="show"
      ><div class="" style="width: 300px; padding: 10px; font-size: 14px">
        {{ content }}
      </div></van-popup
    >
    <!-- <div class="search-tips">
      <p>热门搜索</p>
      <ul class="list">
        <li v-for="(item, index) in list" :key="index" @click="getDetail(item)">
          {{ item.val }}
        </li>
      </ul>
    </div> -->
  </div>
</template>
<script>
import Search from "@c/search";
import { sousuoApi } from "@/service/api.js";
import Vue from "vue";
import { Toast } from "vant";
import { Dialog } from "vant";

export default {
  name: "index",
  directives: {
    focus: {
      inserted: function(el, { value }) {
        console.log(el, { value });
        if (value) {
          el.focus();
        }
      }
    }
  },
  data() {
    return {
      placeholderVal: "搜索科室/医生/疾病",
      list: [
        { val: "妇科" },
        { val: "男科" },
        { val: "张医生" },
        { val: "国际医疗中心" }
      ],
      key: "",
      apptoken: "",
      list: "",
      doclist: [],
      show: false,
      content: ""
      // keyup:""
    };
  },
  components: {
    Search
  },
  created() {
    this.apptoken = JSON.parse(localStorage.getItem("apptoken"));
    this.key = JSON.parse(localStorage.getItem("key"));
    if (this.key) {
      this.go(this.key);
    }
    // console.log(this.key)
  },
  methods: {
    getDetail(val) {
      this.searchSub(val.val);
    },
    goInfo(el) {
      this.show = true;
      this.content = el;
    },
    gosearch(val) {
      console.log(val);
    },
    go(val) {
      var reg = /^\S+$/;
      var seamsg = "";
      if (val) {
        if (!reg.test(val)) {
          seamsg = "所在医院不能带空格";
          Toast("内容不能有空格");
        }
        if (seamsg == "") {
          sousuoApi({
            apptoken: this.apptoken,
            word: val
          }).then(res => {
            console.log(res);
            this.list = res.data;
            this.doclist = res.data.list;
          });
        }
      } else {
        Toast("内容不能为空");
      }
    },
    godoctor(item) {
      window.localStorage.removeItem("hosid");

      this.$router.push({
        name: "choose_doctor",
        query: {
          departmentName: item.departmentName,
          departmentId: item.departmentId,
          hospitalId: item.hospitalId
        }
      });
    },
    godocinfo(item) {
      this.$router.push({
        name: "doctor_info",
        query: {
          doctorId: item.doctorId,
          departmentId: item.departmentId
          // departmentName: this.departmentName,
        }
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.bg-content {
  background: #f6f6f6;
}
.search-c {
  position: relative;
  display: flex;
  margin-top: 10px;
  .seaimg {
    position: absolute;
    top: 10px;
    left: 20px;
    width: 15px;
    height: 15px;
  }
  .search {
    width: 72%;
    height: 35px;
    border: none;
    border-radius: 5px 0 0 5px;
    background-color: #fff;
    font-size: 12px;
    margin-left: 10px;
    padding-left: 30px;
  }
  .go {
    height: 35px;
    line-height: 35px;
    font-size: 12px;
    color: #fff;
    background-color: #01d2bd;
    border-radius: 0 5px 5px 0;
    width: 50px;
    text-align: center;
  }
}

.nav {
  width: 90%;
  padding: 10px;
  display: flex;
  .line {
    width: 5px;
    height: 20px;
    background-color: #01d2bd;
  }
  .tuijian {
    font-size: 16px;
    margin-left: 5px;
    color: #333;
    font-weight: bold;
  }
}
.search-tips p {
  margin: 0 16px;
  font-size: 14px;
  font-family: PingFang SC;
  font-weight: 500;
  color: #1c1c1c;
  line-height: 35px;
}
.list {
  padding: 10px;
  li {
    display: inline-block;
    height: 20px;
    background: #ededed;
    border-radius: 10px;
    font-size: 12px;
    font-family: Source Han Sans CN;
    font-weight: 400;
    color: #888888;
    line-height: 23px;
    text-align: center;
    line-height: 20px;
    margin: 6px 4px;
    padding: 4px 20px;
  }
}
.search-list {
  width: 100%;
  background-color: #fff;

  .item {
    width: 100%;
    //  padding: 10px;
    padding-top: 10px;
    padding-bottom: 10px;
    display: flex;
    border-bottom: 1px solid #ccc;
    .img {
      width: 50px;
      height: 50px;
      // background-color: gray;
      border-radius: 50%;
      margin-left: 10px;
      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }
    .docinfo {
      margin-left: 10px;
      .name {
        font-size: 16px;
        font-weight: bold;
        span {
          margin-left: 5px;
          font-size: 14px;
          // font-weight: 600;
          color: #999;
        }
      }
      .hosname {
        font-size: 14px;
        font-weight: 500;
        color: #999;
      }
      .goodinfo {
        width: 280px;
        font-size: 14px;
        font-weight: 500;
        color: #999;

        display: flex;
        justify-content: space-between;
        .good-left {
          width: 220px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .good-right {
        }
      }
      .jiuzhennum {
        font-size: 14px;
        font-weight: 500;
        color: #999;
      }
    }
  }
}
</style>
